/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package sie_invdis;

import org.jfree.ui.ApplicationFrame;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.GradientPaint;
import org.jfree.chart.ChartFactory;

import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;

import org.jfree.chart.axis.CategoryAxis;
import org.jfree.chart.axis.CategoryLabelPositions;

import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.PlotOrientation;

import org.jfree.chart.renderer.category.BarRenderer;
import org.jfree.data.category.CategoryDataset;
import org.jfree.data.category.DefaultCategoryDataset;

import org.jfree.ui.ApplicationFrame;


import org.jfree.chart.renderer.category.LineAndShapeRenderer;

import javax.swing.JOptionPane;
import java.awt.*;
import java.awt.event.*;


import org.jfree.chart.plot.DefaultDrawingSupplier;
import org.jfree.chart.plot.DrawingSupplier;
import java.awt.geom.Rectangle2D;


import java.util.Date;
import java.util.Calendar;
import java.text.SimpleDateFormat;
import java.text.ParseException;

import javax.swing.Timer;
import java.text.*;
import org.jfree.data.category.DefaultCategoryDataset;
//import org.jfree.ui.Spacer;
/**
 *
 * @author Michelle
 */
public class ventas_sie_cortes_graficacion_line extends ApplicationFrame{

     public ventas_sie_cortes_graficacion_line(String title,DefaultCategoryDataset datasetxy,String granombre,String granombreorizo) {

        super(title);

        //final XYDataset dataset = createDataset();
        final JFreeChart chart = createChart(datasetxy,granombre,granombreorizo);
        final ChartPanel chartPanel = new ChartPanel(chart);
        chartPanel.setPreferredSize(new java.awt.Dimension(800,600));
        setContentPane(chartPanel);

    }
/*
      private XYDataset createDataset() {
       XYSeries series1=null;
       XYSeriesCollection dataset = new XYSeriesCollection();

        series1 = new XYSeries("First");

        series1.add(1.0, 1.0);
        series1.add(2.0, 4.0);
        series1.add(3.0, 3.0);
        series1.add(4.0, 5.0);
        series1.add(5.0, 5.0);
        series1.add(6.0, 7.0);
        series1.add(7.0, 7.0);
        series1.add(8.0, 8.0);
        dataset.addSeries(series1);
        //final XYSeries series2 = new XYSeries("Second");
        series1 = new XYSeries("Second");
        series1.add(1.0, 5.0);
        series1.add(2.0, 7.0);
        series1.add(3.0, 6.0);
        series1.add(4.0, 8.0);
        series1.add(5.0, 4.0);
        series1.add(6.0, 4.0);
        series1.add(7.0, 2.0);
        series1.add(8.0, 1.0);

        dataset.addSeries(series1);

        //final XYSeries series3 = new XYSeries("Third");
        series1 = new XYSeries("Third");
        series1.add(3.0, 4.0);
        series1.add(4.0, 3.0);
        series1.add(5.0, 2.0);
        series1.add(6.0, 3.0);
        series1.add(7.0, 6.0);
        series1.add(8.0, 3.0);
        series1.add(9.0, 4.0);
        series1.add(10.0, 3.0);
        dataset.addSeries(series1);
        
      

        return dataset;

    }
*/
    /**
     * Creates a chart.
     *
     * @param dataset  the data for the chart.
     *
     * @return a chart.
     */
    private JFreeChart createChart(CategoryDataset data,String fnombregraf,String fnombreorizo) {

       JFreeChart chart= ChartFactory.createLineChart(
                fnombregraf,        //Nombre de la gráfica
                fnombreorizo,               //Nombre del eje Horizontal
                "Monto de Venta",                  //Nombre del eje vertical
                data,                       //Data
                PlotOrientation.VERTICAL, //Orientación
                true,                       //Incluir leyenda
                true,                       //Información al pasar el mouse
                true);                      //URls
        //         StandardLegend legend = (StandardLegend) chart.getLegend();
        //legend.setDisplaySeriesShapes(true);

        Shape[] shapes = new Shape[3];
        int[] xpoints;
        int[] ypoints;

        // right-pointing triangle
        xpoints = new int[] {-3, 3, -3};
        ypoints = new int[] {-3, 0, 3};
        shapes[0] = new Polygon(xpoints, ypoints, 3);

        // vertical rectangle
        shapes[1] = new Rectangle2D.Double(-2, -3, 3, 6);

        // left-pointing triangle
        xpoints = new int[] {-3, 3, 3};
        ypoints = new int[] {0, -3, 3};
        shapes[2] = new Polygon(xpoints, ypoints, 3);

        final DrawingSupplier supplier = new DefaultDrawingSupplier(
            DefaultDrawingSupplier.DEFAULT_PAINT_SEQUENCE,
            DefaultDrawingSupplier.DEFAULT_OUTLINE_PAINT_SEQUENCE,
            DefaultDrawingSupplier.DEFAULT_STROKE_SEQUENCE,
            DefaultDrawingSupplier.DEFAULT_OUTLINE_STROKE_SEQUENCE,
            shapes
        );
        final CategoryPlot plot = chart.getCategoryPlot();
        plot.setDrawingSupplier(supplier);

        chart.setBackgroundPaint(Color.yellow);

        // set the stroke for each series...
        plot.getRenderer().setSeriesStroke(
            0,
            new BasicStroke(
                2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND,
                1.0f, new float[] {10.0f, 6.0f}, 0.0f
            )
        );
        plot.getRenderer().setSeriesStroke(
            1,
            new BasicStroke(
                2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND,
                1.0f, new float[] {6.0f, 6.0f}, 0.0f
            )
        );
        plot.getRenderer().setSeriesStroke(
            2,
            new BasicStroke(
                2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND,
                1.0f, new float[] {2.0f, 6.0f}, 0.0f
            )
        );

        // customise the renderer...
        final LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer();
//        renderer.setDrawShapes(true);
        renderer.setItemLabelsVisible(true);
  //      renderer.setLabelGenerator(new StandardCategoryLabelGenerator());

        // customise the range axis...
        final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
        rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
        rangeAxis.setAutoRangeIncludesZero(false);
        rangeAxis.setUpperMargin(0.12);
        return chart;

    }
    @Override public void windowClosing(WindowEvent e) {

      //variables_global.setmuestrograficacorte(1);
      //System.out.println("Provando la Actualizacion="+variables_global.getmuestrograficacorte());
      //this.timer.stop();
      this.dispose();



     }

}
